{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    <form action="" method="post" class="form form-horizontal" id="category-add">
        <input type="text" hidden class="input-text" value="0" id="parentId" name="parentId">
        <input type="text" hidden class="input-text" value="true" id="isParent" name="isParent">
        <input type="text" hidden id="inputid" value="{$id}">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">
                <span class="c-red">*</span>
                分类名称：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="" placeholder="" id="name" name="name">
            </div>
        </div>
        
    
      
        <div class="row cl">
            <div class="col-7 col-offset-4">
                <input id="saveButton" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;保存并提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</div>
{/block}
{block name="script"}
<script src="__LIB__/h-ui/js/H-ui.js"></script>
<script src="__STATIC__/js/jquery.validate.js"></script>
<script type="text/javascript">

    
    $('#parentSwitch').on('switch-change', function (e, data) {
        if(data.value==true){
            $("#isParent").val(true);
        }else{
            $("#isParent").val(false);
        }
    });

    //保存发布
    $("#category-add").validate({
        rules:{
            name:{
                required:true,
                minlength:1,
                maxlength:25,
            },
        
        },
        onkeyup:false,
        focusCleanup:false,
        success:"valid",
        submitHandler:function(form){
            var $parentid =$('#inputid').val();
            // console.log($parentid);
            var index = layer.load(3);
            $(form).ajaxSubmit({
                url: "/admin/Demo/addMenu",
                type: "POST",
                data:{
                    'parent_id':$parentid,
                },
                success: function(data) {
                    // console.log(data);
                    index = layer.load(3);
                    layer.close(index);
                    var datas = JSON.parse(data);
                    if(datas.success==true){
                        layer.alert("上传成功",{title:"提示信息",icon:0},function(index){
                            window.location.href="excel";                        
                        });
                       
                    } else {
                        layer.alert("上传失败",{title:"提示信息",icon:0});
                    }
                },
                error:function(XMLHttpRequest) {
                    layer.close(index);
                    layer.alert('数据处理失败! 错误码:'+XMLHttpRequest.status,{title: '错误信息',icon: 2});
                }
            });
        }
    });
</script>
{/block}



